package com.kafkaadmin.controller;
import com.kafkaadmin.springKafkaAdmin.KafkaAdminUtil;
import org.apache.kafka.clients.admin.TopicDescription;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
import java.util.Set;

/**
 * @ClassName
 * @Author: chenyw
 * @Date: 2022/03/01/15:30
 * @Version:
 */
@RestController
@RequestMapping("/kafka")
public class KafkaShowController {

    @Autowired
    private KafkaAdminUtil kafkaAdminUtil;

    /**
     * 查询所有主题
     *
     * @return
     */
    @GetMapping("/findAllTopic")
    public Set<String> findAllTopic() throws Exception {
        return kafkaAdminUtil.listAllTopics();
    }

    /**
     * 创建主题
     *
     * @param topicName
     * @return
     * @throws Exception
     */
    @GetMapping("/createTopic")
    public String createTopic(String topicName) throws Exception {
        return kafkaAdminUtil.createTopic(topicName);
    }

    /**
     * 当前主题详细信息
     *
     * @param topicName
     * @return
     * @throws Exception
     */
    @GetMapping("/describeTopics")
    public Map<String, TopicDescription> describeTopics(String topicName) throws Exception {
        return kafkaAdminUtil.describeTopics(topicName);
    }

    /**
     * 删除指定主题
     * @param topicName
     * @return
     * @throws Exception
     */
    @GetMapping("/deleteTopic")
    public String deleteTopic(String topicName) throws Exception {
        return kafkaAdminUtil.deleteTopic(topicName);
    }
}
